package com.orange.jfreechart.demo;

import java.io.File;
import java.util.Vector;

import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;

public class ChartsMainTest {

    public static void main(String[] args) throws Exception {
        testCreateBarChartVertical();
    }

    public static void testCreateBarChartVertical() throws Exception {
        // 标注类别
        String[] categories = { "集成电路科学与工程学院", "中国科学院", "材料科学与工程学院", "中国工程学院", "物理学院" };
        Vector<Serie> series = new Vector<Serie>();
        // 柱子名称：柱子所有的值集合
        series.add(new Serie("院士", new Double[] { 157.0, 142.0, 120.0, 91.0, 72.0 }));
        // series.add(new Serie("New York",
        // new Double[] { 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5,
        // 106.6, 92.3 }));
        // series.add(new Serie("London",
        // new Double[] { 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2,
        // 59.3, 51.2 }));
        // series.add(new Serie("Berlin",
        // new Double[] { 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1,
        // 46.8, 51.1 }));

        String title = "";
        String categoryAxisLabel = "";
        String valueAxisLabel = "";
        JFreeChart chart = ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, series, categories,
            PlotOrientation.VERTICAL);
        File file = new File("E:\\chart\\testCreateBarChartVertical.jpeg");
        int width = 600;
        int height = 300;
        ChartUtilities.saveChartAsJPEG(file, chart, width, height);
    }

    public static void testCreatePieChart() throws Exception {
        // 标注类别
        String[] categories = { "集成电路科学与工程学院", "中国科学院", "材料科学与工程学院", "中国工程学院", "物理学院" };
        Vector<Serie> series = new Vector<Serie>();
        // 柱子名称：柱子所有的值集合
        series.add(new Serie("院士", new Double[] { 157.0, 142.0, 120.0, 91.0, 72.0 }));
        // series.add(new Serie("New York",
        // new Double[] { 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5,
        // 106.6, 92.3 }));
        // series.add(new Serie("London",
        // new Double[] { 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2,
        // 59.3, 51.2 }));
        // series.add(new Serie("Berlin",
        // new Double[] { 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1,
        // 46.8, 51.1 }));

        String title = "";
        String categoryAxisLabel = "";
        String valueAxisLabel = "";
        JFreeChart chart = ChartFactory.createPieChart(title, categories,
            new Double[] { 157.0, 142.0, 120.0, 91.0, 72.0 });
        File file = new File("E:\\chart\\Pie.jpeg");
        int width = 600;
        int height = 300;
        ChartUtilities.saveChartAsJPEG(file, chart, width, height);
    }

    public static void testCreateBarChart() throws Exception {
        // 标注类别
        String[] categories = { "集成电路科学与工程学院", "中国科学院", "材料科学与工程学院", "中国工程学院", "物理学院" };
        Vector<Serie> series = new Vector<Serie>();
        // 柱子名称：柱子所有的值集合
        series.add(new Serie("院士", new Double[] { 157.0, 142.0, 120.0, 91.0, 72.0 }));
        // series.add(new Serie("New York",
        // new Double[] { 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5,
        // 106.6, 92.3 }));
        // series.add(new Serie("London",
        // new Double[] { 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2,
        // 59.3, 51.2 }));
        // series.add(new Serie("Berlin",
        // new Double[] { 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1,
        // 46.8, 51.1 }));

        String title = "";
        String categoryAxisLabel = "";
        String valueAxisLabel = "";
        JFreeChart chart = ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, series, categories,
            PlotOrientation.HORIZONTAL);
        File file = new File("E:\\chart\\barChart.jpeg");
        int width = 1024;
        int height = 1000;
        ChartUtilities.saveChartAsJPEG(file, chart, width, height);
    }

    public static void testCreateBarChart2() throws Exception {
        // 标注类别
        String[] categories = { "用户组1", "用户组2", "用户组3", "用户组4", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
            "Dec" };
        Vector<Serie> series = new Vector<Serie>();
        // 柱子名称：柱子所有的值集合
        series.add(new Serie("用户组",
            new Double[] { 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4 }));
        series.add(new Serie("New York",
            new Double[] { 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3 }));
        // series.add(new Serie("London",
        // new Double[] { 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2,
        // 59.3, 51.2 }));
        // series.add(new Serie("Berlin",
        // new Double[] { 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1,
        // 46.8, 51.1 }));

        String title = "";
        String categoryAxisLabel = "";
        String valueAxisLabel = "";
        JFreeChart chart = ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, series, categories,
            PlotOrientation.VERTICAL);
        File file = new File("E:\\chart\\barChart.jpeg");
        int width = 1024;
        int height = 1000;
        ChartUtilities.saveChartAsJPEG(file, chart, width, height);
    }
}
